package main

/*
#cgo LDFLAGS: -ldl
#include <dlfcn.h>
*/
import "C"
import "fmt"

func main() {
    // 替换为你的动态链接库路径
    libraryPath := "./libexample.dylib"

    // 加载动态链接库
	fmt.Println("Start to run ...")
    handle := C.dlopen(C.CString(libraryPath), C.RTLD_LAZY)
    defer C.dlclose(handle)

    if handle == nil {
        fmt.Println("Failed to load the library")
        return
    }

    // 调用动态链接库中的函数
    symbolName := "Hello"
    helloSymbol := C.dlsym(handle, C.CString(symbolName))

    if helloSymbol == nil {
        fmt.Println("Failed to find the symbol:", symbolName)
        return
    }

    // 转换为 Go 函数并调用
    hello := C.GoString((*C.char)(helloSymbol))
	fmt.Println("Start to run 222...", hello)
}